// pages/usercenter/usercenter.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
     //控制模态框
    hidden:false,
     // 请求次数
    request_count:0,

    isshow:true,
    show:false,
    search_result_data: [], 
    cxuserinfo:{},
    all_order_data:[],
    data1:[],
    con1:[],
    data2:[],
    con2:[],

    data3:[],
    con3:[],

    data4:[],
    con4:[],

    data5:[],
    con5:[],

    data6:[],
    con6:[],
    //全部订单
    con7:[]
  },
    

  /**
   * 生命周期函数--监听页面加载
   */

  request_order_data(){
   wx.request({
     url: 'http://api_devs.wanxikeji.cn/api/orderList' ,
     method:"post",
     data:{
       "token":wx.getStorageSync('token')
     },
     success:(res)=>{
       console.log( res.data.data.data);
       this.setData({
        all_order_data:res.data.data.data
       })
       console.log(this.data.all_order_data);
       this.control_hidden()
       this.fenli()

     }
   })
  },
  onLoad: function (options) {
    this.request_order_data()
  },
  //控制模态框显示函数
  control_hidden(){
    this.setData({
     request_count:this.data.request_count+1,
    })
    console.log(this.data.request_count);
    // if(this.data.request_count == 1){
    //   this.setData({
    //     hidden:false
    //   })
    // }
   } ,
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  fenli(){
    let arr = [];
    console.log( this.data.all_order_data);
    for(let i = 0;i < this.data.all_order_data.length;i++){
    console.log(123123);

      if(this.data.all_order_data[i].childern != undefined){
        console.log(123);

        for(let j = 0 ;j < this.data.all_order_data[i].childern.length;j++){
          console.log(this.data.all_order_data[i].childern[j]);
          arr.push(this.data.all_order_data[i].childern[j])
            if(this.data.all_order_data[i].childern[j].status ==1){
              this.data.all_order_data[i].childern[j].addres_id = this.data.all_order_data[i].address_id
              this.data.data1.push(this.data.all_order_data[i].childern[j])
            }
            if(this.data.all_order_data[i].childern[j].status ==2){
              this.data.all_order_data[i].childern[j].addres_id = this.data.all_order_data[i].address_id
  
              this.data.data2.push(this.data.all_order_data[i].childern[j])
            }
            if(this.data.all_order_data[i].childern[j].status ==3){
              this.data.all_order_data[i].childern[j].addres_id = this.data.all_order_data[i].address_id
  
              this.data.data3.push(this.data.all_order_data[i].childern[j])
            }
            if(this.data.all_order_data[i].childern[j].status ==4){
              this.data.all_order_data[i].childern[j].addres_id = this.data.all_order_data[i].address_id
  
              this.data.data4.push(this.data.all_order_data[i].childern[j])
            }
            if(this.data.all_order_data[i].childern[j].status ==5){
              this.data.all_order_data[i].childern[j].addres_id = this.data.all_order_data[i].address_id
  
              this.data.data5.push(this.data.all_order_data[i].childern[j])
            }
            if(this.data.all_order_data[i].childern[j].status ==6){
              this.data.all_order_data[i].childern[j].addres_id = this.data.all_order_data[i].address_id
              this.data.data6.push(this.data.all_order_data[i].childern[j])
            }
        }
      }
  
    }
    console.log(arr);
      
    this.setData({
      con1:JSON.stringify(this.data.data1),
      con2:JSON.stringify(this.data.data2),
      con3:JSON.stringify(this.data.data3),
      con4:JSON.stringify(this.data.data4),
      con5:JSON.stringify(this.data.data5),
      con6:JSON.stringify(this.data.data6),
      con7:JSON.stringify(arr)
    })
    // console.log(this.data.con1);
    // console.log(this.data.con2);
    // console.log(this.data.con3);
    // console.log(this.data.con4);
    // console.log(this.data.con5);
    // console.log(this.data.con6);
    console.log(this.data.con7);
  
  },
   
  onReady: function () {
  },
  to_product_detail(e){
    let item = e.currentTarget.dataset.item;
    console.log(item);
    wx.navigateTo({
      url: '../product_detail/product_detail?state=3&good_id='+item.good_id,
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
 
  onShow: function () {
    const userinfo = wx.getStorageSync('CXuserinfo');
    this.setData({userinfo});
    if(userinfo !== ''){
      this.setData({
        isshow:false,
        show:true,
      });
    }else{
      this.setData({
        isshow:true,
        show:false,
      })
    };
    this.goodList();
  },

  //商品列表
  goodList(){
    let that = this;
    let token = wx.getStorageSync('token');
    wx.request({
      url: 'http://api_devs.wanxikeji.cn/api/goodList',
      method:'POST',
      data:{
        'page':'1',
        'size':'10'   
      },
      success:function(res){
          // console.log(res.data.data.data);
          that.setData({
            search_result_data: res.data.data.data
          })
      }
  });
  }
 
 
})

